package com.zerdoor.timertask;

import com.zerdoor.service.ItemProgressService;
import org.springframework.beans.factory.annotation.Autowired;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimerTask;

/**
 * Created by zhongjieyu on 2015/2/9.
 */
public class ItemProgressTimeTask extends TimerTask {


    @Autowired
    private ItemProgressService itemProgressService;

    @Override
    public void run() {

        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        System.out.println("定时器开始执行。");
        System.out.println("时间：" + dateFormat.format(new Date()));

        try {

            //任务项目维护
            itemProgressService.updateMaintenanceItemProgress();

            //竞赛活动维护
            itemProgressService.updateMaintenanceRaceProgress();

        } catch (Exception e) {

            new Exception("定时器自动维护任务进度时出错，请检查。");
            e.printStackTrace();
        }

        System.out.println("定时器执行结束。");
    }
}
